#include "linked_list.h"



void list_node_init( struct list_node *src )
{
	src->last = src ;
	src->next = src ;
}

void list_insert_after( struct list_node *src, struct list_node *obj )
{
	src->next->last = obj ;
	obj->next = src->next ;
	src->next = obj ;
	obj->last = src ;
}

void list_insert_before( struct list_node *src, struct list_node *obj )
{
	src->last->next = obj ;
	obj->last = src->last ;
	src->last = obj ;
	obj->next = src ;
}

void list_remove_node( struct list_node *obj )
{
	obj->last->next = obj->next ;
	obj->next->last = obj->last ;
	obj->next = obj ;
	obj->last = obj ;
}

void list_single_init( struct list_single_node*src )
{
	src->next = src ;
}

void list_single_insert( struct list_single_node *src, struct list_single_node *obj )
{
	obj->next = src->next ;
	src->next = obj ;
}

void list_single_remove( struct list_single_node *head_ptr, struct list_single_node *obj )
{
	struct list_single_node *ptr = head_ptr ; 
	/* find obj node and change obj last node de next equal obj de next */
	while ( 1 )
	{
		if ( ptr->next == obj )
		{
			ptr->next = obj->next ;
			obj->next = obj ;
			break;
		}
		else if (( ptr->next == 0 )||( ptr->next = head_ptr ))
		{
			break ;
		}
		else
		{
			ptr = ptr->next ;
		}
	}
}














